package com.novel.frame.lxf;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.management.StringValueExp;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;

import com.novel.bean.Mybookshelf;
import com.novel.bean.User;
import com.novel.db.BaseDao;
import com.novel.frame.lgw.Notice;
import com.novel.frame.lgw.StackRoom;
import com.novel.frame.wxl.RankingFrame;
import com.novel.frame.wxl.WelfareFrame;
import com.novel.frame.yf.My_bookshelf;
import com.novel.frame.yf.Person_center;

/**
 * 小说框架
 */
public class Login_Panel extends JFrame {

	private JScrollPane sp_center;// 总滚动面板

	private JPanel pl_ALL;// 总面板

	/*
	 * 上部固定面板
	 */
	private JPanel pl_north;// 上部固定面板

	private JPanel pl_north_north;// 上部固定面板上部
	private JLabel lb_BookSeaGirlNet;// 书海女生网按钮
	private JLabel lb_BookSeaGirlNetPart;// 书海女生网按钮隔开线
	private JLabel lb_BookSeaLiteratureNet;// 书海文学网按钮
	private JLabel lb_BookSeaLiteratureNetPart;// 书海文学网按钮隔开线
	private JLabel lb_BookSeaComicNet;// 书海动漫网按钮
	private JLabel lb_register;// 注册按钮
	private JLabel lb_registerPart;// 注册按钮隔开线
	private JLabel lb_help;// 帮助按钮
	private JLabel lb_helpPart;// 帮助按钮隔开线
	private JLabel lb_north_login;// 登录按钮
	private JLabel lb_north_loginPart;// 登录按钮隔开线
	private JLabel lb_Client;// 客户端按钮

	private JPanel pl_north_center;// 上部固定面板中部
	private JLabel lb_BooksSea;// 书海标签
	private JLabel lb_HotSearch;// 热搜标签
	private JTextField tf_Search;// 搜索文本域
	private JLabel lb_Search;// 搜索按钮
	private JLabel lb_SearchTips;// 搜索提示
	private JLabel lb_Recharge;// 充值按钮
	private JLabel lb_WritersCenter;// 作家中心按钮
	private JLabel lb_center_loginMail;// 中部登录邮件图像
	private JLabel lb_center_loginHeadPicture;// 中部登录头像

	private JPanel pl_north_south;// 上部固定面板下部
	private JLabel lb_FirstPage;// 首页按钮
	private JLabel lb_FirstPagePart;// 首页按钮隔开线
	private JLabel lb_StackRoom;// 书库按钮
	private JLabel lb_StackRoomPart;// 书库按钮隔开线
	private JLabel lb_Ranking;// 排行按钮
	private JLabel lb_RankingPart;// 排行按钮隔开线
	private JLabel lb_IpSpecialArea;// IP专区按钮
	private JLabel lb_IpSpecialAreaPart;// IP专区按钮隔开线
	private JLabel lb_WriterWelfare;// 作家福利按钮
	private JLabel lb_WriterWelfarePart;// 作家福利按钮隔开线
	private JLabel lb_AnnounceInformation;// 公告资讯按钮
	private JLabel lb_AnnounceInformationPart;// 公告资讯按钮隔开线
	private JLabel lb_GirlSpecialArea;// 女生专区按钮
	private JLabel lb_GirlSpecialAreaPart;// 女生专区按钮隔开线
	private JLabel lb_MyBookShelf;// 我的书架按钮

	/*
	 * 中部面板以及中部切换面板：首页、排行、登录、我的书库、注册
	 */
	private JPanel pl_center;// 中部总面板
	private JPanel pl_centerleft;// 中部切换面板左面板
	private JPanel pl_centerright;// 中部切换面板右面板
	
	/*
	 * 登录面板
	 */
	private JPanel pl_login;// 登录面板
	private JPanel pl_login_north;// 登录上面板
	private JPanel pl_login_north_left;// 登录上面板左
	private JLabel lb_login_userlogin;// 用户登录文字

	private JPanel pl_login_north_right;// 登录上面板右
	private JLabel lb_login_userregister;// 用户注册文字

	private JPanel pl_login_center;// 登录下面板
	
	private JPanel pl_login_center_left;// 登录下面板左部
	private JLabel lb_login_username;// 用户名
	private JTextField ta_login_username;// 用户名输入框
	private JLabel lb_login_usernameErrorTip;// 用户名输入错误提示
	private JLabel lb_login_password;// 密码
	private JPasswordField pf_login_password;// 密码输入框
	private JLabel lb_login_passwordErrorTip;// 密码输入错误提示
	private JLabel lb_login_verificode;// 验证码
	private JTextField ta_login_verificode;// 验证码输入框
	private JLabel lb_login_verificodeErrorTip;// 验证码输入错误提示
	private JLabel lb_login_VerificodePicture;// 验证码图片
	private static String login_validCode;//验证码
	private CodeMaker codeMaker = new CodeMaker();//验证码图片生成工具
	private JLabel lb_login_VerificodePictureTxt;// 验证码更换文字
	private JCheckBox cb_remenberuser;// 记住账号单选框
	private JLabel lb_remenberuser;// 记住账号文字
	private JLabel lb_login_login;// 登录账号按钮

	private JPanel pl_login_center_right;// 登录下面板右部
	private JLabel lb_login_registertips;// 注册账号提示
	private JLabel lb_login_register;// 注册账号按钮
	
	private JPanel pl_login_south;// 登录下面板
	private JLabel lb_login_south_youqinglianjie;// 登录下面板友情链接图片
	
	private static BaseDao baseDao=new BaseDao();
	private Map<String, String> LoginInformation=new HashMap<String, String>();//存放登录的信息
	private static final long serialVersionUID = 1L;
	private static List<String> LoginUserName=new ArrayList<String>();//储存所有的Username
	
	//获取磁盘的最后一个磁盘：登录验证码
		private static String loginSavePath = "";
		static {
			File[] roots = File.listRoots();
			loginSavePath = roots[roots.length-1].getPath();
			File file = new File(loginSavePath+="/validCodesImgs/");
			//判断文件夹是否存在，不存在则创建
			if (file == null || !file.exists()) {
				file.mkdirs();
			}
		}
		//获取磁盘的最后一个磁盘：注册验证码
				private static String registerSavePath = "";
				static {
					File[] roots = File.listRoots();
					registerSavePath = roots[roots.length-1].getPath();
					File file = new File(registerSavePath+="/validCodesImgs/");
					//判断文件夹是否存在，不存在则创建
					if (file == null || !file.exists()) {
						file.mkdirs();
					}
				}
	public Login_Panel() {
		// 设置总布局
		JFrame jf = new JFrame("书海小说网");
		jf.setLayout(new BorderLayout());
		jf.setIconImage(Toolkit.getDefaultToolkit().createImage(Login_Panel.class.getResource("./LXFimg/主题.jpg")));

		// 获取屏幕分辨率
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		int ScreenWidth = dimension.width;
		int ScreenHeight = dimension.height;

		// 界面总面板
		pl_ALL = new JPanel();
		pl_ALL.setLayout(new BorderLayout());
		pl_ALL.setPreferredSize(new Dimension(ScreenWidth, (int)(ScreenHeight*1.2)));

		// 滑动总面板
		sp_center = new JScrollPane();
		sp_center.getViewport().add(pl_ALL);
		//设置滚动条滑动速度
		sp_center.getVerticalScrollBar().setUnitIncrement(30);
		jf.add(sp_center);

		// 上部总面板
		pl_north = new JPanel();
		pl_north.setLayout(new BorderLayout());
		pl_north.setPreferredSize(new Dimension(0, (int) (ScreenHeight * 0.2)));
		pl_north.setBackground(Color.white);
		pl_ALL.add(BorderLayout.NORTH, pl_north);

		// 上部面板上部
		pl_north_north = new JPanel();
		pl_north_north.setLayout(null);
		pl_north_north.setPreferredSize(new Dimension(0, (int) (ScreenHeight * 0.2 * 0.2)));
		pl_north_north.setBackground(new Color(189, 183, 107));
		pl_north.add(BorderLayout.NORTH, pl_north_north);
		Font font = new Font("微软雅黑", Font.PLAIN, 12);

		// 书海女神网按钮
		lb_BookSeaGirlNet = new JLabel("书海女生网");
		lb_BookSeaGirlNet.setFont(font);
		lb_BookSeaGirlNet.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_BookSeaGirlNet.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_BookSeaGirlNet.setForeground(Color.black);
		lb_BookSeaGirlNet.setBounds((int) (ScreenWidth * 0.125), (int) (ScreenHeight * 0.2 * 0.2 * 0), 60, 30);
		pl_north_north.add(lb_BookSeaGirlNet);

		// 书海女神网按钮隔开线
		lb_BookSeaGirlNetPart = new JLabel("|");
		lb_BookSeaGirlNetPart.setFont(font);
		lb_BookSeaGirlNetPart.setForeground(Color.black);
		lb_BookSeaGirlNetPart.setBounds((int) (ScreenWidth * 0.175), (int) (ScreenHeight * 0.2 * 0.2 * 0), 10, 30);
		pl_north_north.add(lb_BookSeaGirlNetPart);

		// 书海文学网按钮
		lb_BookSeaLiteratureNet = new JLabel("书海文学网");
		lb_BookSeaLiteratureNet.setFont(font);
		lb_BookSeaLiteratureNet.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_BookSeaLiteratureNet.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_BookSeaLiteratureNet.setForeground(Color.black);
		lb_BookSeaLiteratureNet.setBounds((int) (ScreenWidth * 0.185), (int) (ScreenHeight * 0.2 * 0.2 * 0), 60, 30);
		pl_north_north.add(lb_BookSeaLiteratureNet);

		// 书海女神网按钮隔开线
		lb_BookSeaLiteratureNetPart = new JLabel("|");
		lb_BookSeaLiteratureNetPart.setFont(font);
		lb_BookSeaLiteratureNetPart.setForeground(Color.black);
		lb_BookSeaLiteratureNetPart.setBounds((int) (ScreenWidth * 0.235), (int) (ScreenHeight * 0.2 * 0.2 * 0), 10,
				30);
		pl_north_north.add(lb_BookSeaLiteratureNetPart);

		// 书海动漫网按钮
		lb_BookSeaComicNet = new JLabel("书海动漫网");
		lb_BookSeaComicNet.setFont(font);
		lb_BookSeaComicNet.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_BookSeaComicNet.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_BookSeaComicNet.setForeground(Color.black);
		lb_BookSeaComicNet.setBounds((int) (ScreenWidth * 0.245), (int) (ScreenHeight * 0.2 * 0.2 * 0), 60, 30);
		pl_north_north.add(lb_BookSeaComicNet);

		// 注册按钮
		lb_register = new JLabel("注册");
		lb_register.setFont(font);
		lb_register.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_register.setForeground(Color.black);
		lb_register.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Register_Jpanel();
				jf.dispose();
			}
		});
		lb_register.setBounds((int) (ScreenWidth * 0.72), (int) (ScreenHeight * 0.2 * 0.2 * 0), 30, 30);
		pl_north_north.add(lb_register);

		// 注册按钮隔开线
		lb_registerPart = new JLabel("|");
		lb_registerPart.setFont(font);
		lb_registerPart.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_registerPart.setForeground(Color.black);
		lb_registerPart.setBounds((int) (ScreenWidth * 0.745), (int) (ScreenHeight * 0.2 * 0.2 * 0), 10, 30);
		pl_north_north.add(lb_registerPart);

		// 登录按钮
		lb_north_login = new JLabel("登录");
		lb_north_login.setFont(font);
		lb_north_login.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new  Login_Panel();
				jf.dispose();
			}
		});
		lb_north_login.setForeground(Color.red);
		lb_north_login.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_north_login.setBounds((int) (ScreenWidth * 0.755), (int) (ScreenHeight * 0.2 * 0.2 * 0), 30, 30);
		pl_north_north.add(lb_north_login);

		// 登录按钮隔开线
		lb_north_loginPart = new JLabel("|");
		lb_north_loginPart.setFont(font);
		lb_north_loginPart.setForeground(Color.black);
		lb_north_loginPart.setBounds((int) (ScreenWidth * 0.78), (int) (ScreenHeight * 0.2 * 0.2 * 0), 10, 30);
		pl_north_north.add(lb_north_loginPart);

		// 帮助按钮
		lb_help = new JLabel("帮助");
		lb_help.setFont(font);
		lb_help.setForeground(Color.black);
		lb_help.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_help.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_help.setBounds((int) (ScreenWidth * 0.79), (int) (ScreenHeight * 0.2 * 0.2 * 0), 30, 30);
		pl_north_north.add(lb_help);

		// 帮助按钮隔开线
		lb_helpPart = new JLabel("|");
		lb_helpPart.setFont(font);
		lb_helpPart.setForeground(Color.black);
		lb_helpPart.setBounds((int) (ScreenWidth * 0.815), (int) (ScreenHeight * 0.2 * 0.2 * 0), 10, 30);
		pl_north_north.add(lb_helpPart);

		// 客户端按钮
		lb_Client = new JLabel("客户端");
		lb_Client.setFont(font);
		lb_Client.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_Client.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_Client.setForeground(Color.black);
		lb_Client.setBounds((int) (ScreenWidth * 0.825), (int) (ScreenHeight * 0.2 * 0.2 * 0), 40, 30);
		pl_north_north.add(lb_Client);

		// 上部面板中部
		pl_north_center = new JPanel();
		pl_north_center.setLayout(null);
		pl_north_center.setBackground(Color.white);
		pl_north.add(BorderLayout.CENTER, pl_north_center);

		// 上部面板中部书海图片
		lb_BooksSea = new JLabel();
		lb_BooksSea.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/书海标题.png")));
		lb_BooksSea.setBounds((int) (ScreenWidth * 0.105), (int) (ScreenHeight * 0.2 * 0.6 * 0.2), 150, 60);
		pl_north_center.add(lb_BooksSea);

		// 上部面板热搜图片
		lb_HotSearch = new JLabel();
		lb_HotSearch.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/首页热搜图片.png")));
		lb_HotSearch.setBounds((int) (ScreenWidth * 0.375), (int) (ScreenHeight * 0.2 * 0.6 * 0.2), 200, 20);
		pl_north_center.add(lb_HotSearch);

		// 搜索文本框
		tf_Search = new JTextField();
		tf_Search.setFont(font);
		tf_Search.setBounds((int) (ScreenWidth * 0.375), (int) (ScreenHeight * 0.2 * 0.6 * 0.44), 225, 30);
		pl_north_center.add(tf_Search);

		// 上部面板输入提示图片
		lb_SearchTips = new JLabel();
		lb_SearchTips.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/输入提示标签.png")));
		lb_SearchTips.setBounds((int) (ScreenWidth * 0.375), (int) (ScreenHeight * 0.2 * 0.6 * 0.7), 225, 30);
		pl_north_center.add(lb_SearchTips);

		// 上部面板搜索按钮图片
		lb_Search = new JLabel();
		lb_Search.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/搜索按钮.png")));
		lb_Search.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_Search.setBounds((int) (ScreenWidth * 0.54), (int) (ScreenHeight * 0.2 * 0.6 * 0.44), 50, 30);
		pl_north_center.add(lb_Search);

		// 上部面板充值按钮
		lb_Recharge = new JLabel();
		lb_Recharge.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_Recharge.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_Recharge.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/充值图片.png")));
		lb_Recharge.setBounds((int) (ScreenWidth * 0.69), (int) (ScreenHeight * 0.2 * 0.6 * 0.2), 80, 25);
		pl_north_center.add(lb_Recharge);

		// 上部面板作家中心按钮
		lb_WritersCenter = new JLabel();
		lb_WritersCenter.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_WritersCenter.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_WritersCenter.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/作家中心图片.png")));
		lb_WritersCenter.setBounds((int) (ScreenWidth * 0.69), (int) (ScreenHeight * 0.2 * 0.6 * 0.5), 80, 25);
		pl_north_center.add(lb_WritersCenter);

		// 上部面板邮件图像登录按钮
		lb_center_loginMail = new JLabel();
		lb_center_loginMail.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_center_loginMail.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Login_Panel();
				jf.dispose();
			}
		});
		lb_center_loginMail.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/邮箱图片登录图片.png")));
		lb_center_loginMail.setBounds((int) (ScreenWidth * 0.77), (int) (ScreenHeight * 0.2 * 0.6 * 0.4), 25, 20);
		pl_north_center.add(lb_center_loginMail);

		// 上部面板登录头像图片
		lb_center_loginHeadPicture = new JLabel();
		lb_center_loginHeadPicture.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_center_loginHeadPicture.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Login_Panel();
				jf.dispose();
			}
		});
		lb_center_loginHeadPicture.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/登录注册按钮.png")));
		lb_center_loginHeadPicture.setBounds((int) (ScreenWidth * 0.81), (int) (ScreenHeight * 0.2 * 0.6 * 0.3), 50,
				40);
		pl_north_center.add(lb_center_loginHeadPicture);

		// 上部面板下部
		pl_north_south = new JPanel();
		pl_north_south.setLayout(null);
		pl_north_south.setBackground(new Color(178, 34, 34));
		pl_north_south.setPreferredSize(new Dimension(0, (int) (ScreenHeight * 0.2 * 0.2)));
		pl_north.add(BorderLayout.SOUTH, pl_north_south);

		// 标题文字格式
		font = new Font("微软雅黑", Font.PLAIN, 15);
		// 首页按钮
		lb_FirstPage = new JLabel("首页");
		lb_FirstPage.setFont(font);
		lb_FirstPage.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new FirstPage_Jpanel(null,false);
				jf.dispose();
			}
		});
		lb_FirstPage.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_FirstPage.setForeground(Color.white);
		lb_FirstPage.setBounds((int) (ScreenWidth * 0.16), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 30, 30);
		pl_north_south.add(lb_FirstPage);

		// 首页隔开按钮
		lb_FirstPagePart = new JLabel("|");
		lb_FirstPagePart.setFont(font);
		lb_FirstPagePart.setForeground(Color.white);
		lb_FirstPagePart.setBounds((int) (ScreenWidth * 0.21), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_FirstPagePart);

		// 书库按钮
		lb_StackRoom = new JLabel("书库");
		lb_StackRoom.setFont(font);
		lb_StackRoom.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_StackRoom.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new StackRoom(null,false);
				jf.dispose();
			}
		});
		lb_StackRoom.setForeground(Color.white);
		lb_StackRoom.setBounds((int) (ScreenWidth * 0.24), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 30, 30);
		pl_north_south.add(lb_StackRoom);

		// 书库隔开标签
		lb_StackRoomPart = new JLabel("|");
		lb_StackRoomPart.setFont(font);
		lb_StackRoomPart.setForeground(Color.white);
		lb_StackRoomPart.setBounds((int) (ScreenWidth * 0.29), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_StackRoomPart);

		// 排行按钮
		lb_Ranking = new JLabel("排行");
		lb_Ranking.setFont(font);
		lb_Ranking.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_Ranking.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new RankingFrame(LoginInformation.get("username"), true);
				jf.dispose();
			}
		});
		lb_Ranking.setForeground(Color.white);
		lb_Ranking.setBounds((int) (ScreenWidth * 0.325), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 30, 30);
		pl_north_south.add(lb_Ranking);

		// 排行隔开标签
		lb_RankingPart = new JLabel("|");
		lb_RankingPart.setFont(font);
		lb_RankingPart.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_RankingPart.setForeground(Color.white);
		lb_RankingPart.setBounds((int) (ScreenWidth * 0.37), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_RankingPart);

		// IP专区按钮
		lb_IpSpecialArea = new JLabel("IP专区");
		lb_IpSpecialArea.setFont(font);
		lb_IpSpecialArea.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_IpSpecialArea.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_IpSpecialArea.setForeground(Color.white);
		lb_IpSpecialArea.setBounds((int) (ScreenWidth * 0.4), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 60, 30);
		pl_north_south.add(lb_IpSpecialArea);

		// IP专区按钮隔开线
		lb_IpSpecialAreaPart = new JLabel("|");
		lb_IpSpecialAreaPart.setFont(font);
		lb_IpSpecialAreaPart.setForeground(Color.white);
		lb_IpSpecialAreaPart.setBounds((int) (ScreenWidth * 0.455), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_IpSpecialAreaPart);

		// 作家福利按钮
		lb_WriterWelfare = new JLabel("作家福利");
		lb_WriterWelfare.setFont(font);
		lb_WriterWelfare.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new WelfareFrame();
				jf.dispose();
			}
		});
		lb_WriterWelfare.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_WriterWelfare.setForeground(Color.white);
		lb_WriterWelfare.setBounds((int) (ScreenWidth * 0.485), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 60, 30);
		pl_north_south.add(lb_WriterWelfare);

		// 作家福利按钮隔开线
		lb_WriterWelfarePart = new JLabel("|");
		lb_WriterWelfarePart.setFont(font);
		lb_WriterWelfarePart.setForeground(Color.white);
		lb_WriterWelfarePart.setBounds((int) (ScreenWidth * 0.55), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_WriterWelfarePart);

		// 公告资讯按钮
		lb_AnnounceInformation = new JLabel("公告资讯");
		lb_AnnounceInformation.setFont(font);
		lb_AnnounceInformation.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Notice(null,false);
				jf.dispose();
			}
		});
		lb_AnnounceInformation.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_AnnounceInformation.setForeground(Color.white);
		lb_AnnounceInformation.setBounds((int) (ScreenWidth * 0.58), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 60, 30);
		pl_north_south.add(lb_AnnounceInformation);

		// 公告资讯按钮隔开线
		lb_AnnounceInformationPart = new JLabel("|");
		lb_AnnounceInformationPart.setFont(font);
		lb_AnnounceInformationPart.setForeground(Color.white);
		lb_AnnounceInformationPart.setBounds((int) (ScreenWidth * 0.645), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10,
				30);
		pl_north_south.add(lb_AnnounceInformationPart);

		// 女生专区按钮
		lb_GirlSpecialArea = new JLabel("女生专区");
		lb_GirlSpecialArea.setFont(font);
		lb_GirlSpecialArea.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_GirlSpecialArea.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "该功能正在建设中");
			}
		});
		lb_GirlSpecialArea.setForeground(Color.white);
		lb_GirlSpecialArea.setBounds((int) (ScreenWidth * 0.675), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 60, 30);
		pl_north_south.add(lb_GirlSpecialArea);

		// 女生专区按钮隔开线
		lb_GirlSpecialAreaPart = new JLabel("|");
		lb_GirlSpecialAreaPart.setFont(font);
		lb_GirlSpecialAreaPart.setForeground(Color.white);
		lb_GirlSpecialAreaPart.setBounds((int) (ScreenWidth * 0.74), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 10, 30);
		pl_north_south.add(lb_GirlSpecialAreaPart);

		// 我的书架按钮
		lb_MyBookShelf = new JLabel("我的书架");
		lb_MyBookShelf.setFont(font);
		lb_MyBookShelf.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JOptionPane.showMessageDialog(null, "请先登录！");
			}
		});
		lb_MyBookShelf.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_MyBookShelf.setForeground(Color.white);
		lb_MyBookShelf.setBounds((int) (ScreenWidth * 0.77), (int) (ScreenHeight * 0.2 * 0.2 * 0.05), 60, 30);
		pl_north_south.add(lb_MyBookShelf);
		/*
		 * ======================================中部切换面板=================================
		 * =======
		 */
		// 中部面板
		pl_center = new JPanel();
		pl_center.setLayout(new BorderLayout());
		pl_center.setBackground(Color.white);
		pl_ALL.add(BorderLayout.CENTER, pl_center);

		// 中部切换面板左面板
		pl_centerleft = new JPanel();
		pl_centerleft.setBackground(Color.white);
		pl_centerleft.setPreferredSize(new Dimension((int) (ScreenWidth * 0.125), 0));
		pl_center.add(BorderLayout.WEST, pl_centerleft);

		// 中部切换面板右面板
		pl_centerright = new JPanel();
		pl_centerright.setBackground(Color.white);
		pl_centerright.setPreferredSize(new Dimension((int) (ScreenWidth * 0.15), 0));
		pl_center.add(BorderLayout.EAST, pl_centerright);
		
/*============================================================================================ */
		
		/*
		 * 中部切换面板中面板
		 */
		// 登录面板
		pl_login = new JPanel();
		pl_login.setBackground(Color.white);
		pl_login.setLayout(new BorderLayout());
		pl_login.setBorder(new LineBorder(Color.gray));
		pl_center.add(BorderLayout.CENTER,pl_login);

		// 转图第一页
		ImageIcon ScrollPicture = new ImageIcon(FirstPage_Jpanel.class.getResource("./LXFimg/首页转图第一页.jpg"));
		// 登录上面板
		pl_login_north = new JPanel();
		pl_login_north.setLayout(new BorderLayout());
		pl_login_north.setBorder(new LineBorder(Color.GRAY));
		pl_login_north.setPreferredSize(new Dimension(0, 30));
		pl_login_north.setBackground(Color.white);
		pl_login.add(BorderLayout.NORTH, pl_login_north);

		// 登录上面板左
		pl_login_north_left = new JPanel();
		pl_login_north_left.setLayout(null);
		pl_login_north_left.setBorder(new LineBorder(Color.GRAY));
		pl_login_north_left.setPreferredSize(new Dimension(ScrollPicture.getIconWidth(), 0));
		pl_login_north_left.setBackground(Color.white);
		pl_login_north.add(BorderLayout.WEST, pl_login_north_left);
		// 用户登录文字
		lb_login_userlogin = new JLabel("用户登录");
		lb_login_userlogin.setFont(new Font("楷体", Font.PLAIN, 15));
		lb_login_userlogin.setForeground(Color.black);
		lb_login_userlogin.setBounds(10, 0, 100, 30);
		pl_login_north_left.add(lb_login_userlogin);

		// 登录上面板右
		pl_login_north_right = new JPanel();
		pl_login_north_right.setLayout(null);
		pl_login_north_right.setBorder(new LineBorder(Color.GRAY));
		pl_login_north_right.setBackground(Color.white);
		pl_login_north.add(BorderLayout.CENTER, pl_login_north_right);
		// 用户注册文字
		lb_login_userregister = new JLabel("用户注册");
		lb_login_userregister.setFont(new Font("楷体", Font.PLAIN, 15));
		lb_login_userregister.setForeground(Color.black);
		lb_login_userregister.setBounds(10, 0, 100, 30);
		pl_login_north_right.add(lb_login_userregister);

		// 登录中面板
		pl_login_center = new JPanel();
		pl_login_center.setLayout(new BorderLayout());
		pl_login_center.setBorder(new LineBorder(Color.GRAY));
		pl_login_center.setBackground(Color.white);
		pl_login.add(BorderLayout.CENTER, pl_login_center);
		
		// 输入框内文字格式
		Font font2 = new Font("微软雅黑", Font.PLAIN, 13);

		// 登录中面板左
		pl_login_center_left = new JPanel();
		pl_login_center_left.setLayout(null);
		pl_login_center_left.setBorder(new LineBorder(Color.GRAY));
		pl_login_center_left.setPreferredSize(new Dimension(ScrollPicture.getIconWidth(), 0));
		pl_login_center_left.setBackground(Color.white);
		pl_login_center.add(BorderLayout.WEST, pl_login_center_left);
		// 用户名文字
		lb_login_username = new JLabel("用户名:");
		lb_login_username.setFont(font);
		lb_login_username.setBounds((int)(ScrollPicture.getIconWidth()*0.1), 50, 50, 30);
		pl_login_center_left.add(lb_login_username);
		
		// 用户名文字输入框
		ta_login_username = new JTextField();
		ta_login_username.setBorder(new LineBorder(Color.black));
		ta_login_username.setFont(font2);
		ta_login_username.setBounds((int)(ScrollPicture.getIconWidth()*0.19), 50, 200, 25);
		ta_login_username.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				//重新添加文本域的光标
				ta_login_username.setFocusable(true);
				ta_login_username.setBorder(new LineBorder(Color.blue));
			}
			@Override
			public void mouseExited(MouseEvent e) {
			//移除光标
			ta_login_username.setFocusable(false);
			String username=ta_login_username.getText();
			if (username==null||username.equals("")) {
				ta_login_username.setBorder(new LineBorder(Color.red));
				lb_login_usernameErrorTip
				.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板昵称未输入提示.png")));
			}else {
				ta_login_username.setBorder(new LineBorder(Color.black));
				lb_login_usernameErrorTip
				.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板单个通过标签.png")));
			}
			LoginInformation.put("username", username);
			}
		});
		pl_login_center_left.add(ta_login_username);
		
		// 用户名未输入错误提示
		lb_login_usernameErrorTip = new JLabel();
		lb_login_usernameErrorTip.setBounds((int) (ScrollPicture.getIconWidth() * 0.48), 40, 120, 30);
		pl_login_center_left.add(lb_login_usernameErrorTip);

		// 密码文字
		lb_login_password = new JLabel("密码:");
		lb_login_password.setFont(font);
		lb_login_password.setBounds((int)(ScrollPicture.getIconWidth()*0.12), 90, 50, 30);
		pl_login_center_left.add(lb_login_password);
		// 密码文字输入框
		pf_login_password = new JPasswordField();
		pf_login_password.setBorder(new LineBorder(Color.black));
		pf_login_password.setFont(font2);
		pf_login_password.setEchoChar('•');
		pf_login_password.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				pf_login_password.setFocusable(true);
				pf_login_password.setBorder(new LineBorder(Color.blue));
			}
			@Override
			public void mouseExited(MouseEvent e) {
			pf_login_password.setFocusable(false);
			 String password=pf_login_password.getText();
			if (password==null||password.equals("")) {
				pf_login_password.setBorder(new LineBorder(Color.red));
				lb_login_passwordErrorTip
				.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板密码未输入提示.png")));
			}else {
				pf_login_password.setBorder(new LineBorder(Color.black));
				lb_login_passwordErrorTip.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板单个通过标签.png")));
			}
			LoginInformation.put("password", password);
			}
		});
		pf_login_password.setBounds((int)(ScrollPicture.getIconWidth()*0.19), 93, 200, 25);
		
		pl_login_center_left.add(pf_login_password);
		// 密码未输入错误提示
		lb_login_passwordErrorTip = new JLabel();
		lb_login_passwordErrorTip.setBounds((int) (ScrollPicture.getIconWidth() * 0.48), 85, 120, 30);
		pl_login_center_left.add(lb_login_passwordErrorTip);
		
		// 验证码文字
		lb_login_verificode = new JLabel("验证码:");
		lb_login_verificode.setFont(font);
		lb_login_verificode.setBounds((int)(ScrollPicture.getIconWidth()*0.1), 130, 50, 30);
		pl_login_center_left.add(lb_login_verificode);
		// 验证码文字输入框
		ta_login_verificode = new JTextField();
		ta_login_verificode.setBorder(new LineBorder(Color.black));
		ta_login_verificode.setFont(font2);
		ta_login_verificode.setBounds((int)(ScrollPicture.getIconWidth()*0.19), 130, 200, 25);
		ta_login_verificode.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				ta_login_verificode.setFocusable(true);
				ta_login_verificode.setBorder(new LineBorder(Color.blue));
			}
			@Override
			public void mouseExited(MouseEvent e) {
			ta_login_verificode.setFocusable(false);
			String verifCode = ta_login_verificode.getText();
			if (verifCode != null && !"".equals(verifCode)) {
					ta_login_verificode.setBorder(new LineBorder(Color.black));
					lb_login_verificodeErrorTip.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板单个通过标签.png")));
			} else {
				ta_login_verificode.setBorder(new LineBorder(Color.red));
				lb_login_verificodeErrorTip
				.setIcon(new ImageIcon(Register_Jpanel.class.getResource("./LXFimg/注册面板验证码未输入提示.png")));
			}
			LoginInformation.put("verifCode", verifCode);
			}
		});
		pl_login_center_left.add(ta_login_verificode);
		
		// 验证码图片
		lb_login_VerificodePicture = new JLabel();
		createLoginValidCodes();
		lb_login_VerificodePicture.setBounds((int)(ScrollPicture.getIconWidth()*0.19)+205, 128,100, 30);
		lb_login_VerificodePicture.setCursor(new Cursor(Cursor.HAND_CURSOR));
		pl_login_center_left.add(lb_login_VerificodePicture);

		// 验证码切换
		lb_login_VerificodePictureTxt = new JLabel("换一张");
		lb_login_VerificodePictureTxt.setFont(new Font("微软雅黑", Font.PLAIN, 10));
		lb_login_VerificodePictureTxt.setBounds((int)(ScrollPicture.getIconWidth()*0.63), 147, 30, 15);
		lb_login_VerificodePictureTxt.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_login_VerificodePictureTxt.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				createLoginValidCodes();
			}
		});
		pl_login_center_left.add(lb_login_VerificodePictureTxt);
		
		// 密码未输入错误提示
		lb_login_verificodeErrorTip = new JLabel();
		lb_login_verificodeErrorTip.setBounds((int) (ScrollPicture.getIconWidth() * 0.63), 120, 120, 30);
		pl_login_center_left.add(lb_login_verificodeErrorTip);

		// 记住账号单选框
		cb_remenberuser = new JCheckBox();
		cb_remenberuser.setBorder(new LineBorder(Color.white));
		cb_remenberuser.setBackground(Color.white);
		cb_remenberuser.setBounds((int)(ScrollPicture.getIconWidth()*0.19), 170, 25, 25);
		pl_login_center_left.add(cb_remenberuser);
		// 记住账号文字
		lb_remenberuser = new JLabel("记住我（一个月免登录）");
		lb_remenberuser.setFont(font);
		lb_remenberuser.setBounds((int)(ScrollPicture.getIconWidth()*0.19)+25, 170, 200, 25);
		pl_login_center_left.add(lb_remenberuser);
		// 登录按钮
		lb_login_login = new JLabel();
		lb_login_login.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/登录按钮.png")));
		lb_login_login.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_login_login.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				searchUserNames();
			    for (int i = 0; i < LoginUserName.size(); i++) {
			    	if (LoginInformation.get("username").equals(LoginUserName.get(i))) {
						if (("["+LoginInformation.get("password")+"]").equals(String.valueOf(searchUserPassword(LoginUserName.get(i))))){
							if (LoginInformation.get("verifCode").equalsIgnoreCase(login_validCode)) {
								JOptionPane.showMessageDialog(null, "登录成功!");
								new Person_center(LoginInformation.get("username"),true);
								jf.dispose();
								break;
							}else {
								JOptionPane.showMessageDialog(null, "验证码错误!");
								break;
							}
						}else {
							JOptionPane.showMessageDialog(null, "密码错误!");
							break;
						}
					}
			    	if ((i==LoginUserName.size()-1)&&!(LoginInformation.get("username").equals(LoginUserName.get(i)))) {
			    		JOptionPane.showMessageDialog(null, "用户名错误!");
						break;
			    	}
			    	
				}
			}
		});
		lb_login_login.setBounds((int)(ScrollPicture.getIconWidth()*0.19), 190, 150, 50);
		pl_login_center_left.add(lb_login_login);

		// 登录中面板右
		pl_login_center_right = new JPanel();
		pl_login_center_right.setLayout(null);
		pl_login_center_right.setBorder(new LineBorder(Color.GRAY));
		pl_login_center_right.setBackground(Color.white);
		pl_login_center.add(BorderLayout.CENTER, pl_login_center_right);

		// 注册账号提示文字
		lb_login_registertips = new JLabel();
		lb_login_registertips.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/注册账号提示.png")));
		lb_login_registertips.setBounds((int)((ScreenWidth*0.725-ScrollPicture.getIconWidth())*0.2), 100, 150, 30);
		pl_login_center_right.add(lb_login_registertips);

		// 注册账号按钮
		lb_login_register = new JLabel();
		lb_login_register.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lb_login_register.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				new Register_Jpanel();
				jf.dispose();
			}
		});
		lb_login_register.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/立即注册按钮.png")));
		lb_login_register.setBounds((int)((ScreenWidth*0.725-ScrollPicture.getIconWidth())*0.2), 130, 150, 30);
		pl_login_center_right.add(lb_login_register);
		
		// 登录下面板
		pl_login_south = new JPanel();
		pl_login_south.setLayout(null);
		pl_login_south.setPreferredSize(new Dimension(0, (int)(ScreenHeight*1.2*0.8*0.34)));
		pl_login_south.setBackground(Color.white);
		pl_login.add(BorderLayout.SOUTH, pl_login_south);
		
		// 登录下面板
		lb_login_south_youqinglianjie = new JLabel();
		lb_login_south_youqinglianjie.setIcon(new ImageIcon(Login_Panel.class.getResource("./LXFimg/首页友情链接.png")));
		lb_login_south_youqinglianjie.setBounds(0, 0, 988, 234);
		pl_login_south.add(lb_login_south_youqinglianjie);
		
		
		jf.setSize(ScreenWidth, ScreenHeight);// 设置大小
		jf.setVisible(true);// 设置可见
		jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);// 设置可关闭
		jf.setLocationRelativeTo(null);// 居中
	}		
	public void createLoginValidCodes() {
		try {
			//String savePath = URLDecoder.decode(RegFrame.class.getResource("/").getPath(), "utf-8")+"com/zking/reg/validCodeImgs/";
			//生成一张新的验证码图片
			long currTime = System.currentTimeMillis();
			codeMaker.createValidCode(loginSavePath+"/验证码图片"+currTime+".png");//验证码图片"+currTime+".png"
			lb_login_VerificodePicture.setIcon(new ImageIcon(loginSavePath+"/验证码图片"+currTime+".png"));
			//返回真实的验证码
			login_validCode= codeMaker.getValidCode();
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	//查询所有的用户名
	public static void searchUserNames() {
		String sql="select * from  user";
		try {
			LoginUserName=baseDao.ColumnListHandler(String.class, sql, "username");
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				baseDao.CloseConnection();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	//查询用户名相对应的密码
	public static Object searchUserPassword(String username) {
		String sql="select * from user where username='"+username+"'";
		Object password=null;
		try {
			password=baseDao.ColumnListHandler(Object.class, sql, "password");
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				baseDao.CloseConnection();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return password;
	}
	
	public static void main(String[] args) {
		new Login_Panel();
		//System.out.println("测试");
	}
}
